package com.vilen.learn.java7.V3_1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by vilen on 2017/9/23.
 * 如何配置AgentFinder具体实现的问题并没有解决，原本AgentFinderFactory要做的工作还是要找个地方完成。
 */
public class HollywoodServiceWithDI {
    public static List<Agent> getFriendlyAgents(AgentFinder finder) {
        List<Agent> agents = finder.findAllAgents();
        List<Agent> friendlyAgents = filterAgents(agents, "Java Developers");
        return friendlyAgents;
    }

    private static List<Agent> filterAgents(List<Agent> agents, String agentType) {
        List<Agent> filteredAgents = new ArrayList<>();
        for (Agent agent : agents) {
            if (agent.getType().equals("Java Developers")) {
                filteredAgents.add(agent);
            }
        }
        return filteredAgents;
    }
}
